<%@page language="java" contentType="text/html;charset=UTF-8" import="java.sql.*" import="java.lang.Object" import="java.util.Date" import="java.security.MessageDigest"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="Annotation.Cluster.Methods.*"%>
<%@ page import="java.io.*"%>
<%@page import="Annotation.DataBase.*"%>
<%
String ClusterNumber = request.getParameter("cn");
String method = request.getParameter("method");
int methodID = Integer.parseInt(method);
String readingActitity = request.getParameter("readingActitityID");
//int readingActitityID = Integer.parseInt(readingActitity);
//out.println("method="+methodID+"<br>");
//out.println("readingActitityID="+readingActitityID+"<br>");
%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Update the quest result</title>
		<style type="text/css">
			th {text-align:center; vertical-align:top;}
			.source{width:250px; height:400px; padding:10px; border:1px solid #aaaaaa; background:cyan; box-shadow: 10px 10px 5px #dddddd;}
			.divbox{width:250px; height:70px; padding:10px; border:1px solid #aaaaaa; box-shadow: 10px 10px 5px #888888;}
			.items{width:200px; border:2px solid #a1a1a1; padding:5px 5px; background:#dddddd;}
		</style>

		
	</head>
	<body>
		<hr>
		
<% //item10-div0###item12-div0###item11-div2###item9-div2###
	MySQLCommand ss= new MySQLCommand();

	String sqls="SELECT cluster_student_list FROM cluster_info WHERE PK_reading_activity = "+readingActitity+" AND PK_cluster_approach = "+method+";";
		
	ResultSet rss = ss.selectSQL(sqls);

	//out.println(sqls);
	out.println("此頁面是為抓取資料庫資料重新呈現");
	
	switch(methodID){
	case 1:
		out.println("Standard");
		break;
	case 2:
		out.println("Quantitative");
		break;
	case 3:
		out.println("Cosine");
		break;
	case 4:
		out.println("Diffusion");
		break;
	}
	//out.println("上次更新時間:"+rss.getString("updateTime"));
	
	if(rss.next()){
		//has next(), has data already
		
%>
		<table width="600" border="1">			
			<tr>
				<th width="50%" style="padding:5px;">
					<%	
					//int clusterQuantitative=rss.getInt("clusterQuantitative");
					String CSL=rss.getString("cluster_student_list");
					String m[]=CSL.split("###");
					
					int go2=0;
					boolean go=true;
					int stop=0;
					while(go){
						
						boolean isOver=false;
						for(int i = 0; i < m.length ; i++)//共有幾個item==共有幾個學生的意思
						{
							//out.println("剩下的:"+m[i]+"<br>");
							String le[]=m[i].split("-");
							String compare="div"+go2;
							if(compare.equals(le[1]) && isOver==false){
								
								out.print("<div id='" + compare + "' class='divbox'>");
								isOver=true;
							}
							if(compare.equals(le[1]) && isOver==true){
								out.print("<div id='" + le[0] + "' class='items'>");
								out.print(le[0]);
								out.print("</div>");
								
								m[i]="a-a";
								stop++;
							}
						}
						if(isOver){
							out.print("</div><p>");
						}
					
						go2++;
						if(m.length == stop){
							go=false;
							//out.println("yes!");
						}
											
					}//while迴圈
					
					%>
				</th>
				
				
			</tr>				
		</table>	
		
		<form name="form1" id="form1" method="post" action="reviewClusterResult4_recalculate.jsp">
		<table width="600" border="1" >	
			<input type="hidden" id="ClusterNumber" name="ClusterNumber" value=<%=ClusterNumber%>/>
			<input type="hidden" id="methodID" name="methodID" value=<%=method%>/>
			<input type="hidden" id="readingActitityID" name="readingActitityID" value=<%=readingActitity%>/>		
			<tr>
				
				<th width="50%" style="padding:5px;">
	    			<input type="button" id="createCluster" name="create" onClick="numberAdding(event)" value="Edit clusters"/>
					create cluster 還沒做
					<input type="button" id="updateTimeStamp" name="updateTimeStamp" onClick='submit()' value="Update Time Stamp"/>
				</th>
			</tr>	
			<tr>
				<th width="50%" style="padding:5px;">
					Update button: Recalculate the cluster result. It may take some times.
				</th>
			</tr>	
						
		</table>
	    </form>
		
		
<%

	}else{
		//false，doesn't have data
		out.println("沒有資料--照理說應該是不會出現這行");
			
	}
	ss.closeDB();
%>

			
	</body>
	
</html>

